import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Collections;

public class Generator {

    public static String URL = "jdbc:mysql://192.168.59.134:3306/farm?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
    public static String USERNAME = "root";
    public static String PASSWORD = "Sipaote2019@";
    public static String PATH = "D:\\新建文件夹\\farm";
    public static String XMLPATH = PATH+"\\xml";

    public static void main(String[] args) {
        FastAutoGenerator.create(URL, USERNAME, PASSWORD)
                .globalConfig(builder -> {
                    builder.author("gepan") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(PATH); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.farm.project") // 设置父包名
                            .moduleName("client") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, XMLPATH)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(Collections.emptyList()).addTablePrefix("") // 设置需要生成的表名
                            .entityBuilder().enableLombok().entityBuilder()
                            .addTableFills(
                                    new Column("create_time", FieldFill.INSERT),
                                    new Column("update_time", FieldFill.UPDATE)
                            ).build(); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }
}
